Fix culture-dependent timestamp in HTML test report (#5868)#5872
Conversation
The HTML reporter rendered the report timestamp with `dd MMM yyyy, HH:mm:ss 'UTC'` and no `IFormatProvider`, so the localized month abbreviation leaked into the output (e.g. `08 5月 2026, 17:40:20 UTC` on Japanese systems). Switch to standard format strings, which are culture-invariant by spec: `R` (RFC1123) for English UI cultures, `u` (universal sortable) otherwise. Defensive `ToUniversalTime()` so the helper is robust if a future caller passes a non-UTC value.
There was a problem hiding this comment.
Review: Fix culture-dependent timestamp in HTML test report (#5868)
The bug fix is valid — the original "dd MMM yyyy, HH:mm:ss 'UTC'" format without an IFormatProvider is genuinely broken on non-English systems, and this PR correctly diagnoses the root cause.
Main concern: unnecessary branching introduces a new consistency problem
The fix introduces two different output formats depending on the running machine's UI culture:
return CultureInfo.CurrentUICulture.TwoLetterISOLanguageName == "en"
? utc.ToString("R") // "Sun, 10 May 2026 17:40:20 GMT"
: utc.ToString("u"); // "2026-05-10 17:40:20Z"This means two people running the same test suite and sharing the HTML report artifact will see timestamps in different formats. That hurts:
- Reproducibility: CI on an English agent produces a different timestamp format than CI on a Japanese agent.
- Downstream consumers: anything scraping or parsing the HTML report now needs to handle two formats.
- Snapshot tests: if TUnit ever snapshots report output, this will cause flakiness.
Simpler correct fix
The simplest correct approach is to pass CultureInfo.InvariantCulture to the original format string, which preserves the existing human-readable style and changes nothing except making it culture-safe:
Timestamp = DateTimeOffset.UtcNow.ToString("dd MMM yyyy, HH:mm:ss 'UTC'", CultureInfo.InvariantCulture),If a format change is desired for other reasons, a single invariant format is still better than branching:
private static string FormatTimestamp(DateTimeOffset value) =>
value.ToUniversalTime().ToString("u", CultureInfo.InvariantCulture); // "2026-05-10 17:40:20Z"Why this is better: one format, deterministic output, no dependency on the runner machine's locale. Even though DateTimeOffset.ToString("R") is invariant by spec, being explicit with CultureInfo.InvariantCulture removes any ambiguity and makes intent clear to future readers.
Minor note
R format emits GMT where the old code said UTC — the PR acknowledges this as cosmetic, which is fair. Just worth flagging that it is a visible change in the English output.
Summary
The diagnosis and intent are correct. The suggested improvement is to drop the CurrentUICulture branch entirely and use a single invariant format string, which fixes the localization bug without introducing format inconsistency across environments.
Up to standards ✅🟢 Issues
|
Drop CurrentUICulture branch per review feedback. Single deterministic format avoids cross-machine output divergence.
There was a problem hiding this comment.
Follow-up Review
The second commit (8cb0658) addresses the concern raised in the previous review — the CurrentUICulture branch has been dropped entirely.
What changed
The fix is now:
Timestamp = DateTimeOffset.UtcNow.ToString("dd MMM yyyy, HH:mm:ss 'UTC'", CultureInfo.InvariantCulture),This is the minimal, correct approach: pass CultureInfo.InvariantCulture to the existing format string. Output is deterministic regardless of the runner machine's locale, the human-readable style is preserved, and there's no branching on CurrentUICulture.
Minor note: PR description drift
The PR description still references the two-format branching approach (R for English, u for non-English) and the different output examples, but the code no longer does that. The description could be updated to reflect the final implementation, though this doesn't affect correctness.
Overall
The fix is clean, minimal, and directly solves the root cause. No concerns. ✅
Updated [TUnit.Core](https://github.com/thomhurst/TUnit) from 1.43.11 to 1.44.0. <details> <summary>Release notes</summary> _Sourced from [TUnit.Core's releases](https://github.com/thomhurst/TUnit/releases)._ ## 1.44.0 <!-- Release notes generated using configuration in .github/release.yml at v1.44.0 --> ## What's Changed ### Other Changes * Generated mocks live in the same namespace as the mocked type by @thomhurst in thomhurst/TUnit#5870 * Show multi-step test spans in class timeline, align report ordering with execution, and correlate linked OTel activities by @Copilot in thomhurst/TUnit#5847 * fix: don't leak RUC onto Should-style comparer overloads (#5857) by @thomhurst in thomhurst/TUnit#5873 * Fix culture-dependent timestamp in HTML test report (#5868) by @thomhurst in thomhurst/TUnit#5872 * fix(mocks-http): auto-prepend `/` to partial endpoint paths (#5838) by @thomhurst in thomhurst/TUnit#5874 * Replace Report.ExpandClassTimeline with [ClassTimeline] attribute by @thomhurst in thomhurst/TUnit#5875 * feat(assertions): make ShouldAssertion<T> implement IAssertion (#5824) by @thomhurst in thomhurst/TUnit#5876 * feat(mocks): support non-span ref struct out/ref params by @thomhurst in thomhurst/TUnit#5878 * fix(core): fill optional params when invoking MethodDataSource via reflection by @thomhurst in thomhurst/TUnit#5880 * Mocks: structural fix for Mock<T> / mocked-member name collisions by @thomhurst in thomhurst/TUnit#5881 * chore(mocks): promote TUnit.Mocks packages to stable by @thomhurst in thomhurst/TUnit#5877 ### Dependencies * chore(deps): update tunit to 1.43.41 by @thomhurst in thomhurst/TUnit#5863 * chore(deps): update dependency tunit.assertions.fsharp to 1.43.41 by @thomhurst in thomhurst/TUnit#5865 * chore(deps): bump @babel/plugin-transform-modules-systemjs from 7.28.5 to 7.29.4 in /docs by @dependabot[bot] in thomhurst/TUnit#5867 * chore(deps): bump fast-uri from 3.1.0 to 3.1.2 in /docs by @dependabot[bot] in thomhurst/TUnit#5862 **Full Changelog**: thomhurst/TUnit@v1.43.41...v1.44.0 ## 1.43.41 <!-- Release notes generated using configuration in .github/release.yml at v1.43.41 --> ## What's Changed ### Other Changes * feat(playwright): expose default Context/Launch options on settings by @thomhurst in thomhurst/TUnit#5861 * fix(hooks): resolve TestDiscovery hook context type by attribute kind, not method name by @thomhurst in thomhurst/TUnit#5860 ### Dependencies * chore(deps): update tunit to 1.43.38 by @thomhurst in thomhurst/TUnit#5858 **Full Changelog**: thomhurst/TUnit@v1.43.38...v1.43.41 ## 1.43.38 <!-- Release notes generated using configuration in .github/release.yml at v1.43.38 --> ## What's Changed ### Other Changes * feat(playwright): add TUnitPlaywrightSettings defaults by @thomhurst in thomhurst/TUnit#5859 **Full Changelog**: thomhurst/TUnit@v1.43.37...v1.43.38 ## 1.43.37 <!-- Release notes generated using configuration in .github/release.yml at v1.43.37 --> ## What's Changed ### Other Changes * docs: clarify MethodDataSourceAttribute.Factory is source-generator-managed by @Copilot in thomhurst/TUnit#5835 * fix(assertions): skip ref-struct members in IsEquivalentTo (#5841) by @thomhurst in thomhurst/TUnit#5842 * feat(playwright): add composition-based fixtures by @thomhurst in thomhurst/TUnit#5840 ### Dependencies * chore(deps): update tunit to 1.43.11 by @thomhurst in thomhurst/TUnit#5821 * chore(deps): update dependency polyfill to 10.4.0 by @thomhurst in thomhurst/TUnit#5830 * chore(deps): update dependency polyfill to 10.4.0 by @thomhurst in thomhurst/TUnit#5829 * chore(deps): update react to ^19.2.6 by @thomhurst in thomhurst/TUnit#5839 * chore(deps): update dependency polyfill to 10.5.0 by @thomhurst in thomhurst/TUnit#5848 * chore(deps): update dependency polyfill to 10.5.0 by @thomhurst in thomhurst/TUnit#5849 * chore(deps): update aspire to 13.3.0 by @thomhurst in thomhurst/TUnit#5851 * chore(deps): update dependency brace-expansion to v5.0.6 by @thomhurst in thomhurst/TUnit#5853 * chore(deps): update dependency polyfill to 10.5.1 by @thomhurst in thomhurst/TUnit#5854 * chore(deps): update dependency polyfill to 10.5.1 by @thomhurst in thomhurst/TUnit#5855 * chore(deps): update verify to 31.16.3 by @thomhurst in thomhurst/TUnit#5856 **Full Changelog**: thomhurst/TUnit@v1.43.11...v1.43.37 Commits viewable in [compare view](thomhurst/TUnit@v1.43.11...v1.44.0). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Summary
HtmlReporterwas rendering the report timestamp withdd MMM yyyy, HH:mm:ss 'UTC'and noIFormatProvider, so the localized month abbreviation leaked into the output — e.g.08 5月 2026, 17:40:20 UTCon Japanese systems.CultureInfoargument required):R(RFC1123) for English UI cultures,u(universal sortable ISO) otherwise. DefensiveToUniversalTime()so the helper is robust if a future caller passes a non-UTC value.Output examples:
Sun, 10 May 2026 17:40:20 GMT2026-05-10 17:40:20ZNote:
Remits the literalGMT(functionally identical to UTC); the previous output saidUTC. Minor cosmetic change for the English path.Test plan
dotnet build TUnit.EnginecleanCultureInfo.CurrentUICultureset toja-JP, confirm timestamp reads2026-...Z(not5月)en-US, confirm timestamp reads... GMT